/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.click.app.model;

/**
 *
 * @author ronald
 */

import com.click.app.Functions;
import java.util.Date;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

@Entity
@Table(name = "period_payment_employee")
public class PeriodPaymentEmployee extends BaseObject {

    private static final long serialVersionUID = 1L;
    private Long id;
    private Double initAmount;
    private Double amountWon;
    private Double amountPayment;
    
    private Double currentAmount; // saldo
    private Double endAmount;
    private Double discount;
    private Date initDate;
    private Date endDate;
    private Boolean closed;
    private Employee employee;
    private List<BalanceEmployee> balanceEmployess;
    private List<PaymentsCut> paymentsCuts;
    private List<PaymentsPant> paymentsPants;
    private Role role;

    @Column(name="closed")
    public Boolean getClosed() {
        return closed;
    }

    public void setClosed(Boolean closed) {
        this.closed = closed;
    }

    @Column(name="discount")
    public Double getDiscount() {
        return Functions.getDouble3Decimal(discount);
    }

    public void setDiscount(Double discount) {
        this.discount = Functions.getDouble3Decimal(discount);
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "id_employee", referencedColumnName = "id_user")
    public Employee getEmployee() {
        return employee;
    }

    public void setEmployee(Employee employee) {
        this.employee = employee;
    }

    @Column(name="amount_payment")
    public Double getAmountPayment() {
        return Functions.getDouble3Decimal(amountPayment);
    }

    public void setAmountPayment(Double amountPayment) {
        this.amountPayment = Functions.getDouble3Decimal(amountPayment);
    }

    @Column(name="amount_won")
    public Double getAmountWon() {
        return Functions.getDouble3Decimal(amountWon);
    }

    public void setAmountWon(Double amountWon) {
        this.amountWon = Functions.getDouble3Decimal(amountWon);
    }


    @Column(name="end_amount")
    public Double getEndAmount() {
        return Functions.getDouble3Decimal(endAmount);
    }

    public void setEndAmount(Double endAmount) {
        this.endAmount = Functions.getDouble3Decimal(endAmount);
    }

    @Temporal(javax.persistence.TemporalType.DATE)
    @Column(name="end_date", length=50)
    public Date getEndDate() {
        return endDate;
    }

    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    @Column(name="id_period_payment_employee", unique=true, nullable=false)
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }
    
    @Column(name="current_amount")
    public Double getCurrentAmount() {
        return Functions.getDouble3Decimal(currentAmount);
    }

    public void setCurrentAmount(Double currentAmount) {
        this.currentAmount = Functions.getDouble3Decimal(currentAmount);
    }

    @Column(name="init_amount")
    public Double getInitAmount() {
        return Functions.getDouble3Decimal(initAmount);
    }

    public void setInitAmount(Double initAmount) {
        this.initAmount = Functions.getDouble3Decimal(initAmount);
    }

    @Temporal(javax.persistence.TemporalType.DATE)
    @Column(name="init_date", length=50)
    public Date getInitDate() {
        return initDate;
    }

    public void setInitDate(Date initDate) {
        this.initDate = initDate;
    }
    @OneToMany(mappedBy = "periodPaymentEmployee")
    public List<BalanceEmployee> getBalanceEmployess() {
        return balanceEmployess;
    }

    public void setBalanceEmployess(List<BalanceEmployee> balanceEmployess) {
        this.balanceEmployess = balanceEmployess;
    }

    @OneToMany(mappedBy = "periodPaymentEmployee")
    public List<PaymentsCut> getPaymentsCuts() {
        return paymentsCuts;
    }

    public void setPaymentsCuts(List<PaymentsCut> paymentsCuts) {
        this.paymentsCuts = paymentsCuts;
    }

    @OneToMany(mappedBy = "periodPaymentEmployee")
    public List<PaymentsPant> getPaymentsPants() {
        return paymentsPants;
    }

    public void setPaymentsPants(List<PaymentsPant> paymentsPants) {
        this.paymentsPants = paymentsPants;
    }
    
    @OneToOne(cascade = CascadeType.ALL, fetch=FetchType.LAZY)
    @JoinColumn(name="id_role")
    public Role getRole() {
        return role;
    }

    public void setRole(Role role) {
        this.role = role;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final PeriodPaymentEmployee other = (PeriodPaymentEmployee) obj;
        if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
            return false;
        }
        if (this.initAmount != other.initAmount && (this.initAmount == null || !this.initAmount.equals(other.initAmount))) {
            return false;
        }
        if (this.endAmount != other.endAmount && (this.endAmount == null || !this.endAmount.equals(other.endAmount))) {
            return false;
        }
        if (this.discount != other.discount && (this.discount == null || !this.discount.equals(other.discount))) {
            return false;
        }
        if (this.initDate != other.initDate && (this.initDate == null || !this.initDate.equals(other.initDate))) {
            return false;
        }
        if (this.endDate != other.endDate && (this.endDate == null || !this.endDate.equals(other.endDate))) {
            return false;
        }
        if (this.closed != other.closed && (this.closed == null || !this.closed.equals(other.closed))) {
            return false;
        }
        if (this.employee != other.employee && (this.employee == null || !this.employee.equals(other.employee))) {
            return false;
        }
        if (this.balanceEmployess != other.balanceEmployess && (this.balanceEmployess == null || !this.balanceEmployess.equals(other.balanceEmployess))) {
            return false;
        }
        if (this.paymentsCuts != other.paymentsCuts && (this.paymentsCuts == null || !this.paymentsCuts.equals(other.paymentsCuts))) {
            return false;
        }
        if (this.paymentsPants != other.paymentsPants && (this.paymentsPants == null || !this.paymentsPants.equals(other.paymentsPants))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 89 * hash + (this.id != null ? this.id.hashCode() : 0);
        hash = 89 * hash + (this.initAmount != null ? this.initAmount.hashCode() : 0);
        hash = 89 * hash + (this.endAmount != null ? this.endAmount.hashCode() : 0);
        hash = 89 * hash + (this.discount != null ? this.discount.hashCode() : 0);
        hash = 89 * hash + (this.initDate != null ? this.initDate.hashCode() : 0);
        hash = 89 * hash + (this.endDate != null ? this.endDate.hashCode() : 0);
        hash = 89 * hash + (this.closed != null ? this.closed.hashCode() : 0);
        hash = 89 * hash + (this.employee != null ? this.employee.hashCode() : 0);
        hash = 89 * hash + (this.balanceEmployess != null ? this.balanceEmployess.hashCode() : 0);
        hash = 89 * hash + (this.paymentsCuts != null ? this.paymentsCuts.hashCode() : 0);
        hash = 89 * hash + (this.paymentsPants != null ? this.paymentsPants.hashCode() : 0);
        return hash;
    }

    public String toString() {
        return new ToStringBuilder(this, ToStringStyle.SIMPLE_STYLE).append(this.getId())
                   .append(this.initAmount).append(this.endAmount).append(this.initDate)
                   .append(this.endDate)
                   .toString();
    }

}
